package com.dl.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author by 党桢乐 on 2020/5/14
 */
@RestController
@RequestMapping("/send")
public class productController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 直接模式
     * @param msg
     * @return
     */
    @RequestMapping("/message/{msg}")
    public  String  sendmessge(@PathVariable String msg){
        rabbitTemplate.convertAndSend("dl",msg);
        return "发送成功";
    }

    /**
     * 分列模式
     * @param msg
     * @return
     */
    @RequestMapping("/fanoutmessage/{msg}")
    public  String  sendmessges(@PathVariable String msg){
        System.out.println(msg);
        rabbitTemplate.convertAndSend("dlexchange","",msg);
        return "分列模式发送成功!";
    }
    /**
     * 主题模式
     * @param msg
     * @return
     */
    @RequestMapping("/topicmessage/{msg}")
    public  String  sendmessgess(@PathVariable String msg){
        System.out.println(msg);
        rabbitTemplate.convertAndSend("topicexchange","dl",msg);
        return "主题模式发送成功!";
    }
}
